<!DOCTYPE html>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<link rel="stylesheet" type="text/css" href="{{CDN}}/easyui/themes/default/easyui.css">
		<link rel="stylesheet" type="text/css" href="{{CDN}}/easyui/themes/icon.css">
		<script type="text/javascript" src="{{CDN}}/easyui/jquery.min.js"></script>
		<script type="text/javascript" src="{{CDN}}/easyui/jquery.easyui.min.js"></script>
		<script type="text/javascript" src="{{CDN}}/easyui/locale/easyui-lang-zh_CN.js"></script>
		<script>

		$(function(){
					
			/*表格初始化*/
			$("#grid").datagrid({
				singleSelect:true,
				fit:true,
				fitColumns:true,
				collapsible:true, 
				striped:true,
				rownumbers:true, 
			    columns:[[    
			    	{field:'CK',checkbox:true},
			    	{field:'level_id',title:'level_id',width:100,align:'left'},
			        {field:'level_name',title:'等级名称',width:100,align:'left'},    
			        {field:'level_order',title:'等级顺序',width:50,align:'center'},
			        {field:'level_class',title:'分类',width:200,align:'left'},
			        {field:'level_alias',title:'别名',width:500,align:'left'}
			    ]],
			    url:'/commonDict/personlevel/getPersonLevelList'
			});
			
			//查询按钮
			$("#search_btn").click(function(){
				$("#grid").datagrid('reload');
			});
			
			//添加按钮
			$("#add_btn").click(function(){
				$("#add_dialog").dialog({ 
					title: '添加',    
					width: 700,    
					height: 400,    
					closed: false,    
					cache: false,
			   		modal: true,
			   		buttons:[{
						text:'保存',
						iconCls:'icon-save',
						handler:function(){
							$.post("/commonDict/personlevel/insertPersonLevel",parent.getFormJson($('#add_form')),function(response){
									
								if(response != 1){
									$.messager.alert('提示','添加了'+response+'条数据');
								}
								$("#add_dialog").dialog('close');
								$("#grid").datagrid('reload');
							})
						}
					}]
				});
				
				
			});
			
			//修改按钮
			$("#edit_btn").click(function(){
				var rows = $('#grid').datagrid('getSelections');
				if(rows.length<1){
					$.messager.alert('提示','请勾选一条');
					return false;
				}
				$("#edit_level_id").textbox("setValue", rows[0].level_id);
				$("#edit_level_name").textbox("setValue", rows[0].level_name);
				$("#edit_level_order").textbox("setValue", rows[0].level_order);
				$("#edit_level_class").textbox("setValue", rows[0].level_class);
				$("#edit_level_alias").textbox("setValue", rows[0].level_alias);
				
				
				$("#edit_dialog").dialog({ 
					title: '修改',    
					width: 700,    
					height: 500,    
					closed: false,    
					cache: false,
			   		modal: true,
			   		buttons:[{
						text:'保存',
						iconCls:'icon-save',
						handler:function(){
							$.post("/commonDict/personlevel/updatePersonLevel",parent.getFormJson($('#edit_form')),function(response){
								if(rows.length<1){
									$.messager.alert('提示','修改了'+response+'条数据');
									return false;
								}
								$("#edit_dialog").dialog('close');
								$("#grid").datagrid('reload');
							})
						
						}
					}]
				});
			});
			
			$("#del_btn").click(function(){
				var rows = $('#grid').datagrid('getSelections');
				if(rows.length<1){
					$.messager.alert('提示','请勾选一条');
					return false;
				}
				$.post("/commonDict/personlevel/deletePersonLevel",{level_id:rows[0].level_id},function(response){
					if(rows.length<1){
						$.messager.alert('提示','删除了'+response+'条数据');
						return false;
					}
					$("#grid").datagrid('reload');
				})
			});
		});
			
		
		
		</script>
	</head>
	<body class="easyui-layout">
		<!-- 主表格 -->
		<div region="center" border="false">
			
			<table id="grid" data-options="toolbar:'#toolbar'">
                <div id = "toolbar">
                    <a href="#" id="search_btn" class="easyui-linkbutton"	 data-options="iconCls:'icon-search'"  >查询</a>
                    <a href="#" id='add_btn' class="easyui-linkbutton" data-options="iconCls:'icon-add'">新增</a>
                    <a href="#" id='edit_btn' class="easyui-linkbutton" data-options="iconCls:'icon-edit'">编辑</a>
                    <a href="#" id='del_btn' class="easyui-linkbutton" data-options="iconCls:'icon-del'">删除</a>
                </div>

            </table>
		</div>
		
		
		<!-- 一些隐藏的对话框 -->
		<!-- 新增子类页 -->
		<div style="display:none" id="add_dialog">
			<form id ="add_form" method="post" >
				<table width="100%">
					<tr>
						<td align="right" width="20%">等级名称:</td>
						<td width="20%"  align="left" >
							<input class="easyui-textbox"   name="level_name" style="width:300px"  />
						</td>
					<tr>
					</tr>
						<td align="right" width="20%">等级顺序:</td>
						<td width="20%"  align="left">
							<select class="easyui-textbox"  name="level_order" style="width:300px">
						</td>
						<td width="20%" ></td>
					</tr>
					
					</tr>
						<td align="right" width="20%">分类:</td>
						<td width="20%"  align="left">
							<select class="easyui-textbox"  name="level_class" style="width:300px">
						</td>
						<td width="20%" ></td>
					</tr>
					</tr>
						<td align="right" width="20%">别名:</td>
						<td width="20%"  align="left">
							<select class="easyui-textbox"  name="level_alias" style="width:300px">
						</td>
						<td width="20%" ></td>
					</tr>
				</table> 
			</form>
		</div>
		
		<!-- 修改子类页 -->
		<div style="display:none" id="edit_dialog">
			<form id ="edit_form" method="post" >   
				<table width="100%">
					
					<tr style="display:none">
						<td align="right" width="20%">id:</td>
						<td width="20%"  align="left" >
							<input class="easyui-textbox"  id="edit_level_id"  name="level_id" style="width:300px"  />
						</td>
					<tr>
					
					<tr>
						<td align="right" width="20%">等级名称:</td>
						<td width="20%"  align="left" >
							<input class="easyui-textbox"  id="edit_level_name"  name="level_name" style="width:300px"  />
						</td>
					<tr>
					</tr>
						<td align="right" width="20%">等级顺序:</td>
						<td width="20%"  align="left">
							<input class="easyui-textbox"  id="edit_level_order" name="level_order"  style="width:300px" />
						</td>
						<td width="20%" ></td>
					</tr>
					</tr>
						<td align="right" width="20%">分类:</td>
						<td width="20%"  align="left">
							<input class="easyui-textbox" id="edit_level_class" name="level_class" style="width:300px" />
						</td>
						<td width="20%" ></td>
					</tr>
					</tr>
						<td align="right" width="20%">别名:</td>
						<td width="20%"  align="left">
							<input class="easyui-textbox" data-options="multiline:true"  id="edit_level_alias" name="level_alias"
							style="height:160px;width:400px" />
						</td>
						<td width="20%" ></td>
					</tr>
				</table> 
			</form>
		</div> 
		
	</body>
</html>
